//===============================================================================
// Microsoft patterns & practices
// Web Service Software Factory
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.IO;
using System.Diagnostics;

namespace Microsoft.Practices.VisualStudio.Helper
{
	public static class ReflectionHelper
	{
		public static T GetAttribute<T>(ICustomAttributeProvider provider,bool inherit)
		{
			T[] attribs = GetAttributes<T>(provider, inherit);
			if (attribs!=null && attribs.Length == 1)
			{
				return attribs[0];
			}
			return default(T);
		}


		[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
		public static T[] GetAttributes<T>(ICustomAttributeProvider provider, bool inherit)
		{
			object[] attribs = null;
			attribs = provider.GetCustomAttributes(typeof(T), inherit);
			if ( attribs==null )
			{
				return new T[0];
			}
			return Array.ConvertAll<Object, T>(attribs,delegate(object attrib)
				{
					return (T)attrib; 
				});
		}
	}
}
